<template>
  <div class="list-header">
    <mt-loadmore
      :bottom-method="loadBottom"
      :auto-fill="false"
      :bottom-all-loaded="allLoaded"
      ref="loadmore"
    >
      <ul>
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="goToDetail(item)"
        >
          <div class="content">
            <span class="font">
              {{ item.题名 }}
            </span>

            <div class="recommond">
              {{ item.推荐时间 }}
            </div>
          </div>
        </li>
      </ul>
    </mt-loadmore>
  </div>
</template>
<script>
import { getRecommend,pushInfos } from "../../api/message.js";
export default {
  name: "list",
  data() {
    return {
      listData: [],
      queryData: {},
      allLoaded: false,
      pagenow: 1,
      pageCount: null,
      userName: "",
      userId: "",
    };
  },
  created() {
    this.userName = JSON.parse(window.localStorage.userInfo).UserName;
    this.userId = JSON.parse(window.localStorage.userInfo).UserId;
  },
  mounted() {
    this.init();
  },
  methods: {
    goToDetail(item) {
     
      let 类型 =item.类型;
      let url = "";
      let data = JSON.stringify({
        dbcode: item.数据库,
        sysid: item.唯一标识,
        fileName:item.唯一标识,
        dbname:item.来源数据库,
        vsm:item.关键词,
      });
      

      if(类型 ==="0" ) {
        this.$router.push({
            path: "/cnkiDetail",
            query: {
              类型,
              data,
              url,
              tableName:item.数据库,
              name: item.题名,
            }
        })
      }else {
        this.$router.push({
            path: "/detail",
            query: {
              类型,
              data,
              url,
              tableName:item.数据库,
              name: item.题名,
            }
        })
      }
    },
    init() {
      // getRecommend({
      //   infoType: "MyRecommendation",
      //   pageIndex: this.pagenow,
      //   pageSize: 8,
      // }).then((res) => {
      //   if (res.data) {
      //     if (res.data.data) {
      //       this.listData = this.listData.concat(JSON.parse(res.data.data));
      //       this.pageCount = res.data.DataCount;
      //     }
      //   }
      // });
      pushInfos().then((res)=>{
           if (res.data) {
         if (res.data.data) {
             this.listData = this.listData.concat(JSON.parse(res.data.data));
            this.pageCount = res.data.DataCount;
        }
         }
      })
    },
    loadTop() {
      if (this.pagenow === 1) {
        this.allLoaded = false; // 若数据已全部获取完毕
        this.$refs.loadmore.onTopLoaded();
        return;
      }
      this.pagenow--;
      this.init();
    },
    loadBottom() {
      if (this.pageCount - this.pagenow * 8 <= 8) {
        this.allLoaded = true; // 若数据已全部获取完毕
        return;
      }
      this.allLoaded = false;
      this.$refs.loadmore.onBottomLoaded();
      this.pagenow++;
      this.init();
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../assets/css/zyy_phone.css";
@import "../../assets/css/search.css";
.list-header {
  height: calc(100vh - 63px);
  background: #fff;
  overflow-x: hidden;
  overflow-y: auto;
  ul {
    width: 100%;
    margin-top: 10px;
    min-height: calc(100vh - 80px);

    li {
      width: 100%;
      padding: 0 10px;
      // border:1px solid red;
      border-bottom: 1px solid #ddd;
      .img {
        display: inline-block;
        width: 32px;
        height: 32px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .content {
        display: inline-block;
        height: 100%;
        vertical-align: top;
        width: calc(100% - 20px);
        position: relative;
        margin-bottom: 20px;
        margin-top: 20px;
        .font {
          width: calc(100%);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 14px;
          display: inline-block;
          font-weight: 600;
        }
        .i {
          position: absolute;
          right: 0;
          width: 100px;
          text-align: right;
          color: #989898;
        }
      }
      .recommond {
        font-size: 14px;
        margin-top: 5px;
        color: #868686;
      }
      .set {
        margin-top: 5px;
        text-align: right;
        img {
          width: 15px;
          height: 15px;
        }
        .line:nth-child(2) {
          margin-left: 10px;
        }
      }
    }

    li:nth-child(1) {
      margin-top: 10px;
    }

    li:last-child {
      margin-bottom: 0;
    }
  }
}
</style>